<?php

namespace app\log\controller;

use app\property\model\ExamineVisitModel;
use app\user\model\UserModel;
use think\admin\Controller;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class ExamineVisit extends Controller
{
    /**
     * 当前操作数据库
     * @var string
     */
    private string $table = 'UserSign';

    /**
     * 用户访客申请审核日志
     * @auth true
     * @menu true
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function index()
    {
        $this->title = '用户访客申请审核日志';
        $userid = $this->request->get("userid");
        if (!empty($userid)) {
            $user = new UserModel();
            $uid = $user->where(['userid' => $userid])->value("id");
        }

        $phone = $this->request->get("phone");
        if (!empty($phone)) {
            $user = new UserModel();
            $uid = $user->where(['phone' => $phone])->value("id");
        }
        $query = $this->_query(ExamineVisitModel::class);
        if (isset($uid)) {
            $query->where(['uid' => $uid]);
        }

        $query->equal("auth")
            ->like('author')
            ->with(['User','Visit'])
            ->order('id', 'DESC')
            ->page(true, true);
    }
}